﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Fish_Atlantis.CustomerPanel
{
    public partial class CustomerView1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            String search = "Select UserName As 供应商,FisheryName As Fishery,Amount As 数量,Date As 上传时间,Period As 交易时间 " +
                            "From Transaction_Record,Users,Fishery " +
                            "where  Transaction_Record.SupplierID=Users.USerID " +
                            "AND Transaction_Record.FisheryID=Fishery.FisheryID " +
                            "AND CustomerID='" + Session["UserID"].ToString() + "' "+
                            "Order By Period DESC;";
            ds = Helper.GetDataSet(search, "SearchTable");

            GridView1.DataSource = ds;
            GridView1.DataBind();

            //初始化第二个表格：记录按照Fishery分布的数据
            DataSet dsfishery = new DataSet();
            String searchfishery = "Select FisheryName As Fishery,SUM(Amount) As 总数量 " +
                                   "From Transaction_Record,Fishery " +
                                   "Where Transaction_Record.FisheryID=Fishery.FisheryID " +
                                   "AND CustomerID='" + Session["UserID"].ToString() + "' " +
                                   "Group By FisheryName "+
                                   "Order By SUM(Amount) DESC;";
            dsfishery = Helper.GetDataSet(searchfishery, "SearchTable1");

            GridView2.DataSource = dsfishery;
            GridView2.DataBind();

            //初始化第三个表格：记录按照时间分布的总数量
            DataSet dstotal = new DataSet();
            String searchtotal = "Select Year(Period) As 交易年份,Month(Period) As 交易月份,SUM(Amount) As 总数量 " +
                                  "From Transaction_Record " +
                                  "Where CustomerID='" + Session["UserID"].ToString() + "' " +
                                  "Group By Year(Period),Month(Period) "+
                                  "Order By Year(Period),Month(Period) DESC;";
            dstotal = Helper.GetDataSet(searchtotal, "SearchTable2");

            GridView3.DataSource = dstotal;
            GridView3.DataBind();
        }

        protected void Details_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            String search = "Select UserName As 供应商,FisheryName As Fishery,Amount As 数量,Date As 上传时间,Period As 交易时间 " +
                            "From Transaction_Record,Users,Fishery " +
                            "where  Transaction_Record.SupplierID=Users.USerID " +
                            "AND Transaction_Record.FisheryID=Fishery.FisheryID " +
                            "AND CustomerID='" + Session["UserID"].ToString() + "' "+
                            "Order By Period DESC;";
            ds = Helper.GetDataSet(search, "SearchTable");

            GridView1.DataSource = ds;
            GridView1.DataBind();

            DataSet dsfishery = new DataSet();
            String searchfishery = "Select FisheryName As Fishery,SUM(Amount) As 总数量 " +
                                   "From Transaction_Record,Fishery " +
                                   "Where Transaction_Record.FisheryID=Fishery.FisheryID " +
                                   "AND CustomerID='" + Session["UserID"].ToString() + "' " +
                                   "Group By FisheryName " +
                                   "Order By SUM(Amount) DESC;";
            dsfishery = Helper.GetDataSet(searchfishery, "SearchTable1");

            GridView2.DataSource = dsfishery;
            GridView2.DataBind();

            DataSet dstotal = new DataSet();
            String searchtotal = "Select Year(Period) As 交易年份,Month(Period) As 交易月份,SUM(Amount) As 总数量 " +
                                  "From Transaction_Record " +
                                  "Where CustomerID='" + Session["UserID"].ToString() + "' " +
                                  "Group By Year(Period),Month(Period) " +
                                  "Order By Year(Period),Month(Period) DESC;";
            dstotal = Helper.GetDataSet(searchtotal, "SearchTable2");

            GridView3.DataSource = dstotal;
            GridView3.DataBind();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataBind();
        }
    }
}